package com.xz.xzmybatisagent;

import com.xz.xzmybatisagent.socket.SocketCallback;
import com.xz.xzmybatisagent.socket.SocketClient;
import com.xz.xzmybatisagent.socket.SocketConfig;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author DONG.WANG17@HAND-CHINA.COM
 * @since 2025-02-16 14:32
 */
public class SqlSender {
    private final ExecutorService executor = Executors.newCachedThreadPool();
    SocketClient client;

    SqlSender(int port) {
        SocketConfig config = new SocketConfig(port);
        config.setCallback(new SocketCallback() {
            @Override
            public void onMessage(String message) {

            }

            @Override
            public void onError(Exception e) {
                System.err.println("[Sql Sender Client] Error: " + e.getMessage());
            }
        });
        this.client = new SocketClient(config);
        client.start();
    }

    public void sendSql(String sqlData) {
        client.sendData(sqlData);
    }
}

